import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
import com.alibaba.druid.sql.parser.SQLStatementParser;

public class ParserMain {

	public static void main(String[] args) {

		String sql = "select * from user order by id";

		// 新建 MySQL Parser
		SQLStatementParser parser = new MySqlStatementParser(sql);

		// 使用Parser解析生成AST，这里SQLStatement就是AST
		SQLStatement statement = parser.parseStatement();

		// 使用visitor来访问AST
		MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
		statement.accept(visitor);

		System.out.println(visitor.getColumns());
		System.out.println(visitor.getOrderByColumns());
	}
}